#include <iostream>
#include<algorithm>
using namespace std;
int n,a[9]={1,2,3,4,5,6,7,8,9};
int main() {
	scanf("%d",&n);
	do{
		for(int i=0;i<n;i++) printf("%5d",a[i]);
		putchar('\n');
	}while(next_permutation(a,a+n));
	return 0;
}